package com.smart.seckilldemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.smart.seckilldemo.commons.vo.SeckillGoodsVo;
import com.smart.seckilldemo.mapper.GoodMapper;
import com.smart.seckilldemo.mapper.SeckillGoodsMapper;
import com.smart.seckilldemo.pojo.SeckillGoods;
import com.smart.seckilldemo.service.SeckillGoodsService;
import com.smart.seckilldemo.utils.RedisJudgeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Slf4j
@Service
public class SeckillGoodsServiceImpl implements SeckillGoodsService {

    @Resource
    SeckillGoodsMapper seckillGoodsMapper;
    @Resource
    RedisJudgeUtils redisJudgeUtils;
    @Resource
    GoodMapper goodMapper;


    /**
     * 获取库存信息
     * @param goodsId
     * @return
     */
    @Override
    public SeckillGoods getSeckillGoods(Long goodsId) {
        QueryWrapper<SeckillGoods> qw = new QueryWrapper<>();
        qw.eq(SeckillGoods.COL_GOODS_ID,goodsId);
        SeckillGoods seckillGoods = seckillGoodsMapper.selectOne(qw);
        return seckillGoods;
    }

    /**
     * 获取商品信息 包括秒杀信息
     * @param goodId
     * @return
     */
    @Override
    public SeckillGoodsVo finSeckillGoodByGoods(Long goodId) {
        SeckillGoodsVo goodSeckillGoodsVo = seckillGoodsMapper.findGoodSeckillGoodsVo(goodId);
        return goodSeckillGoodsVo;
    }


}
